using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using DTO;
using System.Data;

namespace HeThongDAO
{
    public class HoaDonDAO
    {
        public static DataTable LayDanhSachHoaDon()
        {
            string sql = "SELECT * FROM HOA_DON";
            return Config.AccessHelper.ExecuteQuery(sql);
        }

        public static bool ThemHoaDon(HoaDonDTO hdDTO)
        {
            try
            {
                string sql = "INSERT INTO HOA_DON(MaKhachHang, NgayLapHoaDon) ";
                sql += "VALUES(" + hdDTO.MaKhachHang.ToString() + ",'" + hdDTO.NgayLapHoaDon.ToString() + "')";

                int maHD = (int)Config.AccessHelper.ExecuteNonQuery_Scalar(sql);
                hdDTO.MaHoaDon = maHD;
                return true;
            }
            catch
            {
                return false;
            }
        }

        public static bool CapNhatHoaDon(HoaDonDTO hdDTO)
        {
            try
            {
                string sql = "UPDATE HOA_DON SET ";
                sql += "MaKhachHang = " + hdDTO.MaKhachHang + ", ";
                sql += "NgayLapHoaDon = " + hdDTO.NgayLapHoaDon;
                sql += " WHERE MaHoaDon = " + hdDTO.MaHoaDon;

                Config.AccessHelper.ExecuteNonQuery(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }

        public static bool XoaHoaDon(HoaDonDTO hdDTO)
        {
            try
            {
                string sql = "DELETE FROM HOA_DON ";
                sql += "WHERE MaHoaDon = " + hdDTO.MaHoaDon;

                Config.AccessHelper.ExecuteNonQuery(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }

        public static DataTable DocSchema()
        {
            return Config.AccessHelper.Doc_Cau_Truc("HOA_DON");
        }
    }
}
